<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <br>
      <el-select v-model="customername" @change="HChange" placeholder="请选择姓名">
        <el-option
          v-for="item in customerlist"
          :key="item.id"
          :label="item.customername"
          :value="item.id">
        </el-option>
      </el-select>
    </el-form>

    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="序号">
      </el-table-column>
      <el-table-column
        prop="serialNumber"
        header-align="center"
        align="center"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="nursingName"
        header-align="center"
        align="center"
        label="名称">
      </el-table-column>
       <el-table-column
        prop="servicePrice"
        header-align="center"
        align="center"
        label="价格">
      </el-table-column>
       <el-table-column
        prop="nursenumber"
        header-align="center"
        align="center"
        label="余量">
      </el-table-column>
       <el-table-column
        prop="maturitytime"
        header-align="center"
        align="center"
        label="服务到期日期">
      </el-table-column>
       <!-- <el-table-column
        prop="customerid"
        header-align="center"
        align="center"
        label="状态">
      </el-table-column> -->

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addupdate(scope.row.id)">续费</el-button>
          <!-- <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">移除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './backdown-add-or-update'
  export default {
    data () {
      return {
        customerid:'',
        customername:'',
        backDownList:[],
        levelId: '',
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        addOrUpdateVisible: false,
        customerlist:[]

      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
    },
    created(){
      this.selectcustormer();
    },
    methods: {

      addupdate(){
        

      },

      selectcustormer(){
        this.$http({
          url: this.$http.adornUrl('/customer/customer/listAll/'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.customerlist = data.page.list
            this.totalPage = data.page.totalCount	
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })

      },



      HChange(value){
        this.customerid=value
        this.getDataList(value)
      },
      // 获取数据列表
      getDataList (value) {
        this.$http({
          url: this.$http.adornUrl(`/customernurseitem/customernurseitem/listByCustomerId/${value}`),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.list
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      
    }
  }
</script>
